<?php
class CiutimetablesController extends AppController {

	var $name = 'Ciutimetables';
	
	
	var $paginate = array(
        'limit' => 12,
        'order' => array(
            'Ciutimetable.id' => 'asc'
        )
    );

	function index() {
		$this->Ciutimetable->recursive = 0;
		$this->set('ciutimetables', $this->paginate('Ciutimetable',array('Ciutimetable.id !='=>8))); // No muestra el horario pendiente
	}

	function view($id = null) {
		if (!$id) {
			$this->Session->setFlash(__('Invalid ciutimetable', true));
			$this->redirect(array('action' => 'index'));
		}
		$this->set('ciutimetable', $this->Ciutimetable->read(null, $id));
	}

	function add() {
		if (!empty($this->data)) {
			$this->Ciutimetable->create();
			if ($this->Ciutimetable->save($this->data)) {
				$this->Session->setFlash(__('The ciutimetable has been saved', true));
				$this->redirect(array('action' => 'index'));
			} else {
				$this->Session->setFlash(__('The ciutimetable could not be saved. Please, try again.', true));
			}
		}
	}

	function edit($id = null) {
		if (!$id && empty($this->data)) {
			$this->Session->setFlash(__('Invalid ciutimetable', true));
			$this->redirect(array('action' => 'index'));
		}
		if (!empty($this->data)) {
			if ($this->Ciutimetable->save($this->data)) {
				$this->Session->setFlash(__('The ciutimetable has been saved', true));
				$this->redirect(array('action' => 'index'));
			} else {
				$this->Session->setFlash(__('The ciutimetable could not be saved. Please, try again.', true));
			}
		}
		if (empty($this->data)) {
			$this->data = $this->Ciutimetable->read(null, $id);
		}
	}

	function delete($id = null) {
		if (!$id) {
			$this->Session->setFlash(__('Invalid id for ciutimetable', true));
			$this->redirect(array('action'=>'index'));
		}
		if ($this->Ciutimetable->delete($id)) {
			$this->Session->setFlash(__('Ciutimetable deleted', true));
			$this->redirect(array('action'=>'index'));
		}
		$this->Session->setFlash(__('Ciutimetable was not deleted', true));
		$this->redirect(array('action' => 'index'));
	}
}
